package cn.hhchat.wp.controller;

import cn.hhchat.wp.dto.msg.RMsg;
import cn.hhchat.wp.dto.msg.RMsgFactory;
import cn.hhchat.wp.dto.user.SimpleUser;
import cn.hhchat.wp.entity.RoleEntity;
import cn.hhchat.wp.entity.UserEntity;
import cn.hhchat.wp.enums.RoleEnum;
import cn.hhchat.wp.service.RoleService;
import cn.hhchat.wp.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created this one by HMH on 2017/10/28.
 */
@RequestMapping("/role")
@RestController
public class RoleController {

    @GetMapping("/getAllUserInfo")
    public RMsg getAllUserInfo(){
        List<UserEntity> users = userService.getAll();
        List<SimpleUser> simpleUsers = users.stream().map(UserEntity::toSimpleUser).collect(Collectors.toList());
        return RMsgFactory.ok(simpleUsers);

    }

    @PostMapping("/setAdminInBatch")
    public RMsg setAdmin(@RequestParam List<Long> userIds) {
        List<UserEntity> users = userIds.stream().map(userService::getById).collect(Collectors.toList());
        roleService.setAdminInBatch(users);
        return RMsgFactory.ok();
    }

    @Autowired
    private UserService userService;

    @Autowired
    private RoleService roleService;



}
